package com.xpu.pms.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xpu.pms.comm.http.PageInfo;
import com.xpu.pms.comm.http.QueryPage;
import com.xpu.pms.comm.http.Respond;
import com.xpu.pms.entity.SysRuleEntity;
import com.xpu.pms.mapper.BaseGroupMapper;
import com.xpu.pms.entity.BaseGroupEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import java.util.List;
/**
 * @author 徐立彬
 * @date 2019-11-22
 */
@RestController
@RequestMapping("base/group")
public class BaseGroupController {
    @Autowired
    BaseGroupMapper baseGroupMapper;
    
    @RequestMapping("/all")
    public List<BaseGroupEntity> all() {
        List<BaseGroupEntity> list = baseGroupMapper.selectList(new QueryWrapper<>());
        return list;
    }
    
    @RequestMapping("/add")
    public Respond add(@RequestBody BaseGroupEntity entity) {
        baseGroupMapper.insert(entity);
        return new Respond();
    }
    
    @RequestMapping("/update")
    public Respond update(@RequestBody BaseGroupEntity entity) {
        baseGroupMapper.updateById(entity);
        return new Respond();
    }
    
    @RequestMapping("/del")
    public Respond del(@RequestBody BaseGroupEntity entity) {
        baseGroupMapper.deleteById(entity.getId());
        return new Respond();
    }

    @RequestMapping("/page")
    public Respond page(@RequestBody QueryPage page) {
        long index = page.getPage().getIndex();
        long size = page.getPage().getSize();
        IPage<BaseGroupEntity> ipage = baseGroupMapper.selectPage(new Page<>(index,size),new QueryWrapper<>());
        PageInfo pageInfo = new PageInfo((int)ipage.getCurrent(),(int)ipage.getTotal(),(int)ipage.getSize());
        Respond res = new Respond().setPage(pageInfo).setData(ipage.getRecords());
        return  res;
    }
}
